package com._51cto.healthy.minio;

import com._51cto.healthy.content.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class MinIoController {

    @Autowired
    private MinIoService minIOCService;

    @PostMapping("/img/upload")
    public R<String> uploadFile(@RequestParam("file") MultipartFile file){
        String url = minIOCService.uploadImage(file);
        return  R.success(url,"图片上传成功");
    }

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @RequestMapping("/img/disposal")
    public R disposal(){
        minIOCService.disposal();
        return R.success("垃圾图片已清除！");
    }
}